﻿CREATE FUNCTION [util].[GetHoursFromBitmask]
(@Bitmask INT)
RETURNS NVARCHAR (1024)
AS
BEGIN
	DECLARE @ReturnValue NVARCHAR(1024);
	SET @ReturnValue = N'';

	DECLARE @hour INT;
	SET @hour = 0;
	WHILE(@hour < 24)
	BEGIN
		SET @ReturnValue = @ReturnValue
			+ (CASE (@Bitmask & POWER(2,@hour))
				WHEN 0 THEN N'' 
				ELSE N',' + RIGHT(N'0' + CAST((@hour + 1) AS NVARCHAR(2)),2) + ':00'
			END);
		SET @hour = @hour + 1;
	END
		
	SET @ReturnValue = SUBSTRING(@ReturnValue,2,1024);
		
	RETURN @ReturnValue
END